package com.common.account.config.service;


import com.common.account.service.IAuUserService;
import org.springframework.security.authentication.InternalAuthenticationServiceException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * 登陆操作
 *
 * @author wangguochao
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Resource
    private IAuUserService iAuUserService;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if (StringUtils.isEmpty(username)) {
            throw new InternalAuthenticationServiceException("用户名或密码错误");
        }
        username = username.trim();
        //设置权限
        return iAuUserService.getUserByName(username);
    }
}
